﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Serialization;

namespace ExpressionUtil.Node.Common
{
    /// <summary>
    /// 二元节点
    /// </summary>
    [Serializable]
    internal abstract class BinaryNode : Node, ISerializable
    {
        /// <summary>
        /// 操作数1
        /// </summary>
        protected Node operand1;

        /// <summary>
        /// 操作数2
        /// </summary>
        protected Node operand2;

        /// <summary>
        /// 默认构造函数
        /// </summary>
        public BinaryNode()
            : base()
        {
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="info">要填充数据的 System.Runtime.Serialization.SerializationInfo</param>
        /// <param name="context">此序列化的目标</param>
        public BinaryNode(SerializationInfo info, StreamingContext context)
            : base()
        {
            this.operand1 = (Node)info.GetValue("operand1", typeof(Node));
            this.operand2 = (Node)info.GetValue("operand2", typeof(Node));
        }

        /// <summary>
        /// 获取或设置操作数1
        /// </summary>
        public Node Operand1
        {
            get
            {
                return this.operand1;
            }
            set
            {
                this.operand1 = value;
            }
        }

        /// <summary>
        /// 获取或设置操作数2
        /// </summary>
        public Node Operand2
        {
            get
            {
                return this.operand2;
            }
            set
            {
                this.operand2 = value;
            }
        }

        #region ISerializable 成员
        /// <summary>
        /// 获取对象数据
        /// </summary>
        /// <param name="info">要填充数据的 System.Runtime.Serialization.SerializationInfo</param>
        /// <param name="context">此序列化的目标</param>
        public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            info.AddValue("operand1", this.operand1, typeof(Node));
            info.AddValue("operand2", this.operand2, typeof(Node));
        }

        #endregion
    }
}
